package com.catmiao.rdd.operate.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Serializable;

import java.util.Arrays;
import java.util.List;

/**
 * @author ChengMiao
 * @title: Transfer_01_Map
 * @projectName spark_study
 * @description: TODO
 * @date 2024/11/25 16:27
 */
public class Transfer_18_Action_Serial {

    public static void main(String[] args) throws InterruptedException {

        final SparkConf conf = new SparkConf();
        conf.setAppName("appName");
        conf.setMaster("local[*]");

        final JavaSparkContext jsc = new JavaSparkContext(conf);


        List<String> list = Arrays.asList("Hadoop","Spark","Hive","Flink");
        JavaRDD<String> rdd = jsc.parallelize(list, 2);


        Search search = new Search("H");
        search.match(rdd);
        jsc.close();


    }
}

class Search {

    private String query;
    public Search(String query) {
        this.query = query;
    }

    public void match(JavaRDD<String> rdd) {
        // 值传递 此时 executor不在使用到Search对象
        String q = query;
        rdd.filter(
                i-> i.startsWith(q)
        ).collect().forEach(System.out::println);

    }
}


